package com.sjy.security;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.security.core.SpringSecurityMessageSource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import com.sjy.bean.User;
import com.sjy.dao.userdao;


@Service
public class UserDetailsServiceImpl implements UserDetailsService  {
	Logger logger = LoggerFactory.getLogger(UserDetailsServiceImpl.class);

	@Autowired
	private userdao userdao;

	
	@Override
	public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException  {
		User user = userdao.findByUsername(s);
		if (user == null) {
			throw new UsernameNotFoundException("用户不存在");
		}
	    System.out.println("username:"+user.getUsername()+";password:"+user.getPassword());
	    System.out.println(user.getAuthorities());
		return user;
	}

}
